package com.ehsunbehravesh.mypasswords.gui;

import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.event.*;

/**
 *  Convenience class to request focus on a component.
 *
 *  When the component is added to a realized Window then component will
 *  request focus immediately, since the ancestorAdded event is fired
 *  immediately.
 *
 *  When the component is added to a non realized Window, then the focus
 *  request will be made once the window is realized, since the
 *  ancestorAdded event will not be fired until then.
 */
public class RequestFocusListener implements AncestorListener
{
	public void ancestorAdded(AncestorEvent e)
	{
		JComponent component = (JComponent)e.getComponent();    
    JTextField txt = (JTextField) component;    
    txt.requestFocusInWindow();        
		component.removeAncestorListener( this );
	}

	public void ancestorMoved(AncestorEvent e) {}
	public void ancestorRemoved(AncestorEvent e) {}
}
